Keep programming languages in memory #4376
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request keeps programming languages in memory in a hash table. This greatly reduces the number of queries.
I considered a few different options to do this:
Adding
includes(:programming_languages)
statementsThis would be relevant everywhere activity icons are displayed. This would reduce the numbers of queries by a lot already, but would still be similar to the amount of times
activities
are queried. This would still be a lot of queries for only 18 different programming languages.using Memcached
This would replace database queries by memcached access. Because the queries themselves are small, most of the cost is due to the overhead of contacting a different server. This would not be solved by memcached.
Keeping an in memory hashmap
This is the option I chose. As there are only 18 different languages this won't take that much active memory. It reduces the number of queries to virtually zero.
The downside is the use of class variables in a multi threaded environment, that could be prone to timing related bugs.